package com.jz.netthings.application.providerCost.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jz.netthings.application.providerAllot.bean.ProviderAllot;
import com.jz.netthings.application.providerAllot.bean.QueryProviderAllot;
import com.jz.netthings.application.providerAllot.service.ProviderAllotService;
import com.jz.netthings.application.providerCost.bean.ProviderCost;
import com.jz.netthings.application.providerCost.bean.QueryProviderCost;
import com.jz.netthings.application.providerCost.service.ProviderCostService;
import com.jz.netthings.application.providerCreate.service.ProviderInfoService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-03-18
 */
@RestController
@RequestMapping("adscm/application/providerCost")
public class ProviderCostController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    ProviderCostService providerCostService;

    @RequestMapping("/select")
    public SimpleCoreResponse selectByTime(/*@RequestBody */QueryProviderCost queryProviderCost, HttpServletRequest request) throws AdscmSystemException, IOException {
        Page<ProviderCost> page =new Page<>(queryProviderCost.getCurrentPage(),queryProviderCost.getPageSize());
        Page<ProviderCost>  providerCosts = providerCostService.selectProviderCost(page ,queryProviderCost);
        return new SimpleCoreResponse("200","查询成功" ,providerCosts);
    }
    @RequestMapping("/update")
    public SimpleCoreResponse update(@RequestBody ProviderCost providerCost, HttpServletRequest request) throws AdscmSystemException, IOException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean  result= providerCostService.updateProviderCost(providerCost,token);
        return new SimpleCoreResponse("200","修改成功" ,result);
    }
}

